package org.menacheri.jetserver.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.menacheri.jetserver.app.Game;
import org.menacheri.jetserver.app.GameRoom;
import org.menacheri.jetserver.util.Credentials;


/**
 * The lookup service abstracts away the implementation detail on getting the
 * game objects from the reference key provided by the client. This lookup is
 * now done from a hashmap but can be done from database or any other manner.
 * 
 * @author Abraham Menacherry
 * 
 */
public class LookupService
{
	private final Map<String, GameRoom> refKeyGameRoomMap;

	public LookupService()
	{
		refKeyGameRoomMap = new HashMap<String, GameRoom>();
	}
	
	public LookupService(Map<String, GameRoom> refKeyGameRoomMap)
	{
		this.refKeyGameRoomMap = refKeyGameRoomMap;
	}

	public Game gameLookup(Object gameContextKey)
	{
		Game returnGame = null;
		for(GameRoom game : refKeyGameRoomMap.values()) {
			if(game.getParentGame().getGameName().equals(gameContextKey)) {
				returnGame = game.getParentGame();
				break;
			}
		}
		return returnGame;
	}

	public GameRoom gameRoomLookup(Object gameContextKey)
	{
		return refKeyGameRoomMap.get((String) gameContextKey);
	}

	public Map<String, GameRoom> getRefKeyGameRoomMap()
	{
		return refKeyGameRoomMap;
	}


}
